import 'package:fijkplayer/fijkplayer.dart';
import 'package:flutter/material.dart';
import 'package:player/player.dart';

class VideoView extends StatefulWidget {
  final Player player;

  const VideoView({super.key, required this.player});

  @override
  _VideoViewState createState() => _VideoViewState();
}

class _VideoViewState extends State<VideoView> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: GestureDetector(
      onTap: onTapVideo,
      child: Stack(children: [
        AbsorbPointer(
          /**通过苔widget进行事件拦截*/
          absorbing: true,
          child: FijkView(player: widget.player, fit: FijkFit.cover,),
        ),
        if (widget.player.state == FijkState.paused)
          Align(
              alignment: Alignment.center,
              child: Image.asset(
                'asset/images/ic_start.png',
                width: 70,
                height: 50,
              ))
      ]),
    ));
  }

  void onTapVideo() {
    if (widget.player.state == FijkState.paused) {
      widget.player.start();
    } else {
      widget.player.pause();
    }
    setState(() {});
  }

  @override
  void dispose() {
    super.dispose();
    widget.player.release(); // 释放资源
  }
}
